using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using Spike.ContractBuilder;

namespace Spike.TestHarness
{
    public class TestCaseResult
    {
        public event EventHandler OnUpdated;
        
        public enum STATUS { Ready, Running, Exception, Faulted, Completed };

        private string OutputField = string.Empty;
        private Exception ExceptionField = null;
        private double ElapsedTimeField = 0;
        private STATUS StatusField = STATUS.Ready;

        public TestCaseResult()
        {
        }

        public TestCaseResult(string sampleOutput)
        {
            OutputField = sampleOutput;
        }

        public string Output
        {
            get { return OutputField; }
            set 
            { 
                OutputField = value; 
                StatusField = STATUS.Completed;

                if (OnUpdated != null)
                    OnUpdated(this, EventArgs.Empty);
            }
        }

        public Exception Exception
        {
            get { return ExceptionField; }
            set 
            { 
                ExceptionField = value;
                if (value is FaultException)
                    StatusField = STATUS.Faulted;
                else
                    StatusField = STATUS.Exception;

                OutputField = SerializationHelper<Exception>.SerializeServiceObject(value);

                if (OnUpdated != null)
                    OnUpdated(this, EventArgs.Empty);
            }
        }
        public double ElapsedTime
        {
            get { return ElapsedTimeField; }
            set 
            { 
                ElapsedTimeField = value;

                if (OnUpdated != null)
                    OnUpdated(this, EventArgs.Empty);
            }
        }
        public STATUS Status
        {
            get { return StatusField; }
            set 
            { 
                StatusField = value;

                if (OnUpdated != null)
                    OnUpdated(this, EventArgs.Empty);
            }
        }
    }
}
